#include "generator.h"
#include "yellowSpiderModel.h"

CGenerator::CGenerator()
{
	Init();
}


VOID CGenerator::Init()
{
//	Enemy enemy;
	
	while( !queueEnemy.empty() )
	{
		queueEnemy.pop();
	}
	/*
	enemy.Set( 1,CYellowSpiderModel::GetInstance(),5.0f,0.02f );
	queueEnemy.push(enemy);
	enemy.Set( 1,CYellowSpiderModel::GetInstance(),0.0f,-0.03f );
	queueEnemy.push(enemy);
	enemy.Set( 1,CYellowSpiderModel::GetInstance(),-4.0f,0.04f );
	queueEnemy.push(enemy);
	enemy.Set( 200,CYellowSpiderModel::GetInstance(),4.0f,0.04f );
	queueEnemy.push(enemy);
	enemy.Set( 300,CYellowSpiderModel::GetInstance(),1.0f,0.04f );
	queueEnemy.push(enemy);
	*/
	m_nRate=10;
	m_nCount=0;
}


Enemy CGenerator::GetRandEnemy()
{
	Enemy enemy;
	enemy.Set( -1,NULL,0.0f,0.f );
	float fpOrigin,fpSpeed;
	int present;
	int direct;
	present=rand()%1000;
	int nRand;
	if( present<=m_nRate )
	{
		if( m_nRate<=15 )
		{
			m_nCount++;
		}
		if( m_nCount>=m_nRate*3 )
		{
			m_nCount=0;
			m_nRate++;
		}
		nRand=rand()%1000;
		fpOrigin=(float)nRand/38.0f-13.0f;
		nRand=rand()%1000;
		fpSpeed=(float)nRand/20000.0f+0.01f;
		nRand=rand()%2;
		if( nRand==0 )
		{
			direct=-1;
		}
		else
		{
			direct=1;
		}
		enemy.Set( 0,CYellowSpiderModel::GetInstance(),fpOrigin,fpSpeed*direct );
	}
	return enemy;
}

Enemy CGenerator::GetQueueEnemy( int nTimeCount )
{
	Enemy enemy,temp;
	enemy.Set( -1,NULL,0.0f,0.f );

	if( queueEnemy.empty() )
	{
		return enemy;
	}

	temp=queueEnemy.front();

	if( nTimeCount<temp.nPresent && temp.nPresent>0 )
	{
		return enemy;
	}

	queueEnemy.pop();

	return temp;
}


CGenerator::~CGenerator()
{
	while( !queueEnemy.empty() )
	{
		queueEnemy.pop();
	}
}